home *** CD-ROM | disk | FTP | other *** search
- Path: xanth!mcnc!rutgers!cmcl2!husc6!necntc!ncoast!allbery
- From: chad@anasaz.UUCP
- Newsgroups: comp.sources.misc
- Subject: v03i044: backspace filter
- Keywords: backspace printer filter nroff
- Message-ID: <8806080635.AA08248@csd1.milw.wisc.edu>
- Date: 8 Jun 88 06:35:22 GMT
- Sender: allbery@ncoast.UUCP
- Reply-To: chad@anasaz.UUCP ()
- Organization: DCF Inc, Phoenix AZ
- Lines: 147
- Approved: allbery@ncoast.UUCP
-
- comp.sources.misc: Volume 3, Issue 44
- Submitted-By: "A. Nonymous" <chad@anasaz.UUCP>
- Archive-Name: nobs
-
- [Why not "col -b"? ++bsa]
-
- This is a filter that has probably been written a thousand times, but
- here is another version. It is used to clean up nroff output
- generated for the default TTY37 terminal for printing on a printer
- that cannot backspace (or one that beats itself silly when it does):
- nroff -man foo.1 | nobs > foo.man
- It has been tested on SysVr2, but should work anywhere.
- ----(cut)--------(cut)--------(cut)--------(cut)--------(cut)----
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of shell archive."
- # Contents: Makefile nobs.c
- # Wrapped by chad@anasaz on Tue Jun 7 20:13:35 1988
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'Makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'Makefile'\"
- else
- echo shar: Extracting \"'Makefile'\" \(238 characters\)
- sed "s/^X//" >'Makefile' <<'END_OF_FILE'
- X# %M% for nobs
- X
- XBINDIR = /usr/local/bin
- XTARGET = nobs
- X
- X$(TARGET): nobs.c
- X $(CC) $(CFLAGS) -o $(TARGET) nobs.c
- X
- Xinstall: nobs
- X strip nobs
- X @-rm $(BINDIR)/$(TARGET)
- X ln $(TARGET) $(BINDIR)
- X touch install
- X
- XLint: nobs.c
- X lint -p nobs.c >Lint
- END_OF_FILE
- if test 238 -ne `wc -c <'Makefile'`; then
- echo shar: \"'Makefile'\" unpacked with wrong size!
- fi
- # end of 'Makefile'
- fi
- if test -f 'nobs.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'nobs.c'\"
- else
- echo shar: Extracting \"'nobs.c'\" \(2474 characters\)
- sed "s/^X//" >'nobs.c' <<'END_OF_FILE'
- X/* nobs.c - Simple backspace filter - 1.1 */
- X
- X/*
- X** This program will take lines containing overstrike pragmas of
- X** the form <char><bs><char> and convert them to individual lines of
- X** output with a return but no line feed between them.
- X** Useful in filtering nroff output to line printers that cannot
- X** back space (or on which back spaces are expensive).
- X*/
- X
- X/*
- X** Author:
- X** Chad R. Larson This program is placed in the
- X** DCF, Inc. Public Domain. You may do with
- X** 14623 North 49th Place it as you please.
- X** Scottsdale, AZ 85254
- X*/
- X
- X#include <stdio.h>
- X
- X#define LINESIZE 512 /* maximum line length */
- X#define MAXOVER 8 /* maximum number of overstrikes */
- X
- X/* forward references */
- Xvoid exit();
- Xchar *memset();
- X
- Xstatic char input[LINESIZE]; /* input line buffer */
- Xstatic char output[MAXOVER][LINESIZE]; /* output line buffers */
- X
- Xvoid main()
- X{
- X int line; /* output buffer array index */
- X int in_dex; /* offset into input buffer */
- X int out_dex; /* offset into output buffer */
- X int line_count; /* number of output lines */
- X int strip; /* trailing space strip index */
- X char chr; /* single character storage */
- X
- X /* loop through the input lines */
- X while ( fgets(input, LINESIZE, stdin) != (char *)NULL ) {
- X
- X /* init output buffers to blanks */
- X memset( output, ' ', sizeof(output) );
- X
- X /* slide through input line, dropping bs chars */
- X out_dex = -1; /* reset array pointers */
- X in_dex = 0;
- X line = 0;
- X line_count = 0;
- X
- X while ( ( chr = input[in_dex++] ) && chr != '\n' ) {
- X if (chr != '\b') {
- X line = 0; /* back to main line */
- X output[line][++out_dex] = chr; /* stuff the character */
- X } else { /* got backspace */
- X ++line; /* select output buffer */
- X if (line == MAXOVER) {
- X fprintf(stderr, "Too many overstrikes!\n");
- X exit(1);
- X }
- X output[line][out_dex] = input[in_dex++];
- X line_count = (line_count < line) ? line : line_count;
- X }
- X } /* end of input line */
- X
- X /* print the output buffers */
- X for (line = 0; line <= line_count; line++) {
- X strip = out_dex;
- X while (output[line][strip] == ' ') /* strip trailing spaces */
- X --strip;
- X ++strip; /* point past string end */
- X if (line < line_count) /* new line or return? */
- X output[line][strip] = '\r';
- X else
- X output[line][strip] = '\n';
- X output[line][++strip] = '\0'; /* terminate string */
- X fputs (output[line], stdout); /* print it */
- X }
- X
- X } /* end of file */
- X exit(0);
- X
- X} /* end of main */
- END_OF_FILE
- if test 2474 -ne `wc -c <'nobs.c'`; then
- echo shar: \"'nobs.c'\" unpacked with wrong size!
- fi
- # end of 'nobs.c'
- fi
- echo shar: End of shell archive.
- exit 0
-